package com.zjy.domain.constant;

import com.zjy.common.constant.StringConstant;
import com.zjy.redis.constant.IRedisKey;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @author zhangjianyu
 * email: 578547270@qq.com
 * create_time: 2024-07-21 22:14
 * description:
 */
public enum RedisKeyEnum implements IRedisKey {

    ENTITY("ENTITY", 10 * 24 * 60 * 60L, "实体类"),
    TEST("TEST", 60 * 60L, "测试"),
    USER_TOKEN("USER_TOKEN", 60 * 60 * 24 * 7L, "用户登录token"),
    USER_ROLE("USER_ROLE", 60 * 60 * 24 * 60L, "用户角色关联"),
    USER_PERMISSION("USER_PERMISSION", 60 * 60 * 24 * 7L , "用户权限关联" ),



    ;
    private String key;
    private Long timeOut;
    private String msg;

    RedisKeyEnum(String key, Long timeOut, String msg) {
        this.key = key;
        this.timeOut = timeOut;
        this.msg = msg;
    }

    @Override
    public String getKey() {
        return key;
    }

    public String getKey(String flag, String... stringFlag) {
        if (flag == null) {
            flag = "";
        }
        if (ObjectUtils.isNotEmpty(stringFlag)) {
            String s = stringFlag[0];
            if (StringUtils.isNotBlank(s)) {
                flag = s + StringConstant.COLON + flag;
            }
        }
        if (StringUtils.isNotBlank(flag)) {
            return getKey() + StringConstant.COLON + flag;
        } else {
            return getKey();
        }

    }

    @Override
    public Long getTimeOut() {
        return timeOut;
    }

}
